package com.example.yls.demoa;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by yls on 2019/5/10.
 */

public class Myview extends View {
    private Paint paint=new Paint();

    private int center;

    public Myview(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(5);
        //反锯齿
        paint.setAntiAlias(true);
        //字体大小
        paint.setTextSize(30);
        //填充
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setDither(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //画小球
        canvas.drawCircle(center,center,100,paint);

        //关于y轴和x轴旋转
        /*Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.wuxian);
        canvas.drawBitmap(bitmap,0,0,paint);
        Matrix matrix=new Matrix();
        matrix.setRotate(90,150,150);
        canvas.drawBitmap(bitmap,matrix,paint);
        matrix.setRotate(180,150,150);
        canvas.drawBitmap(bitmap,matrix,paint);
        matrix.setRotate(270,150,150);
        canvas.drawBitmap(bitmap,matrix,paint);
*/
       //关于y轴和x轴缩放，平移
       /* Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.wuxian);
        canvas.drawBitmap(bitmap,0,0,paint);
        Matrix matrix1=new Matrix();
        matrix1.setScale(-1,1);
        matrix1.postTranslate(300,0);
        canvas.drawBitmap(bitmap,matrix1,paint);

        Matrix matrix2=new Matrix();
        matrix2.setScale(1,-1);
        matrix2.postTranslate(0,300);
        canvas.drawBitmap(bitmap,matrix2,paint);

        Matrix matrix3=new Matrix();
        matrix3.setScale(-1,-1);
        matrix3.postTranslate(300,300);
        canvas.drawBitmap(bitmap,matrix3,paint);*/
        /*canvas.drawPoint(100,100,paint);
        canvas.drawLine(100,100,300,500,paint);
        canvas.drawRect(100,100,300,500,paint);
        canvas.drawRoundRect(100,100,300,300,50,50,paint);
        canvas.drawText("软件",100,100,paint);
        //225从哪里开始画，90画多少
        canvas.drawArc(100,100,400,400,225,90,false,paint);*/
        //五角星
        /*Path path=new Path();
        path.moveTo(100,100);
        path.lineTo(300,100);
        path.lineTo(150,300);
        path.lineTo(200,50);
        path.lineTo(250,300);
        path.lineTo(100,100);
        canvas.drawPath(path,paint);
        Point a=new Point(0,100);
        Point b=new Point(300,100);
        Point c=new Point(50,250);
        Point d=new Point(250,250);
        Point e=new Point(150,0);
        Path path=new Path();
        path.moveTo(a.x,a.y);
        path.lineTo(b.x,b.y);
        path.lineTo(c.x,c.y);
        path.lineTo(e.x,e.y);
        path.lineTo(d.x,d.y);
        path.lineTo(a.x,a.y);
        canvas.drawPath(path,paint);*/


    }

    public void setCenter(int center) {
        this.center = center;
        invalidate();
    }


}
